<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="umsroot.css">
<TITLE>
Simulating other System's Delay-Primitives
</TITLE>
</HEAD>
<BODY >
<A HREF="umsroot115.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot104.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc259">17.12</A>&nbsp;&nbsp;Simulating other System's Delay-Primitives</H2>
It is relatively easy to simulate similar constructs from other
systems by using delay clauses,
for example, MU-Prolog's <I>sound negation</I> predicate <CODE>~</CODE>/1
<A NAME="@default1047"></A>
can be in ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> simply implemented as
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
delay ~ X if nonground(X).
~ X :- \+ X .
</PRE></BLOCKQUOTE>
MU-Prolog's <I>wait declarations</I> can be in most cases
simulated using delay clauses.
Although it is not possible to convert all wait declarations
to delay clauses, in the real life examples
this can usually be achieved.
The <I>block</I> declarations of SICStus Prolog can be easily expressed
as delay clauses with <A HREF="../bips/kernel/typetest/var-1.html"><B>var/1</B></A><A NAME="@default1048"></A> and <A HREF="../bips/kernel/typetest/nonground-1.html"><B>nonground/1</B></A><A NAME="@default1049"></A> conditions.
The <I>freeze/2</I> predicate (e.g. from SICStus Prolog, same as
<I>geler/2</I> in Prolog-II) can be expressed as
<A NAME="@default1050"></A>
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
delay freeze(X, _) if var(X).
freeze(_, Goal) :- call(Goal).
</PRE></BLOCKQUOTE>
The transcription of <I>when declarations</I> from NU_Prolog
basically involves negating them:
<A NAME="@default1051"></A>
for instance, the when declarations
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
?- flatten([], _) when ever.
?- flatten(A._, _) when A.
</PRE></BLOCKQUOTE>
can be rewritten as
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
delay flatten(A, _) if var(A).
delay flatten([A|_], _) if var(A).
</PRE></BLOCKQUOTE>
Note that in contrast to when declarations,
there are no syntactic restrictions on the head of a delay clause,
in particular, it can contain any compound terms and repeated variables.
In the clause body, a delay clause allows more flexibility by supporting
programming with (a subset of) builtins.
In general, it is a matter of taste whether specifying delay-conditions
or execute-conditions is more straightforward.
However, the semantics of delay clauses is certainly more intuitive in
that missing delay clauses simply imply no delay, while missing
when-declarations imply a most general 'when ever' declaration.<BR>
<BR>
<HR>
<A HREF="umsroot115.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot104.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
</BODY>
</HTML>
